package com.example.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect // 设置为切面类
@Component
public class RecordTimeAspect {
    @Around("execution(* com.example.service.impl.DeptServiceImpl.*(..))")
    public Object recordTime(ProceedingJoinPoint joinPoint) throws Throwable {
        // 记录方法执行开始的时间
        long begin = System.currentTimeMillis();
        // 执行原始方法
        Object result = joinPoint.proceed();
        // 记录方法结束时间
        long end = System.currentTimeMillis();
        log.info("方法执行耗时：{} ms", end - begin);
        return result;
    }
}